package com.hyts.agent.auto.logger.jul;

import com.hyts.agent.auto.config.DefaultAgentLoggerConfig;
import com.hyts.agent.base.logger.AgentLogger;
import com.hyts.jlogger.manager.LoggerManager;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.agent.base.logger
 * author:Libo/Alex
 * create-date:2019-06-29 22:17
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: java util logging 日志操作
 */

public class DefaultAgentLogger implements AgentLogger {

    /**
     * 操作logger日志输出器
     */
    private Logger logger;

    /**
     * 实例logger日志
     * @param clazz
     * @return
     */
    @Override
    public AgentLogger injectLogger(Class<?> clazz) {
        logger = LoggerManager.getLogger(clazz);
        return this;
    }

    /*@Override
    public Object getLogger() {
        return null;
    }*/
    @Override
    public void info(String message){
        logger.info(addToken(message, DefaultAgentLoggerConfig.DEFAULT_LOGGER_PREFIX, DefaultAgentLoggerConfig.DEFAULT_LOGGER_SUBFIX));
    }
    @Override
    public void debug(String message){
        logger.log(Level.FINE,addToken(message, DefaultAgentLoggerConfig.DEFAULT_LOGGER_PREFIX, DefaultAgentLoggerConfig.DEFAULT_LOGGER_SUBFIX));
    }
    @Override
    public void error(String message){
        logger.log(Level.SEVERE,addToken(message, DefaultAgentLoggerConfig.DEFAULT_LOGGER_PREFIX, DefaultAgentLoggerConfig.DEFAULT_LOGGER_SUBFIX));
    }
    @Override
    public void warn(String message){
        logger.log(Level.WARNING,addToken(message, DefaultAgentLoggerConfig.DEFAULT_LOGGER_PREFIX, DefaultAgentLoggerConfig.DEFAULT_LOGGER_SUBFIX));
    }
    @Override
    public void all(String message){
        logger.log(Level.ALL,addToken(message, DefaultAgentLoggerConfig.DEFAULT_LOGGER_PREFIX, DefaultAgentLoggerConfig.DEFAULT_LOGGER_SUBFIX));
    }
    /**
     * 数值越大 优先级越低
     * @return
     */
    @Override
    public int order() {
        return Integer.MAX_VALUE;
    }

    public DefaultAgentLogger(Logger logger) {
        this.logger = logger;
    }

    public DefaultAgentLogger() {}
}
